var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2EventsMgr = require("EventsMgr");
var $2DataManager = require("DataManager");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_JoyStickBall = /* */function (_cc$Component37) {
  babel_inherits(r, _cc$Component37);
  var _super41 = babel_createSuper(r);
  function r() {
    var _this88;
    babel_classCallCheck(this, r);
    _this88 = _super41.apply(this, arguments);
    _this88.max_r = 95;
    _this88.min_r = 20;
    _this88.dir = cc.v2();
    _this88.stick = null;
    _this88.moving = false;
    _this88.jsctrl = null;
    _this88.start_pos = null;
    _this88.hbdian = null;
    return _this88;
  }
  babel_createClass(r, [{
    key: "onLoad",
    value: function onLoad() {
      this.stick = cc.find("Stick", this.node);
      this.jsctrl = cc.find("jsctrl", this.node.parent);
      this.hbdian = cc.find("hbdian", this.node.parent);
      this.start_pos = this.hbdian.position;
      this.jsctrl.on(cc.Node.EventType.TOUCH_START, this.on_start, this);
      this.jsctrl.on(cc.Node.EventType.TOUCH_MOVE, this.on_move, this);
      this.jsctrl.on(cc.Node.EventType.TOUCH_END, this.on_end, this);
      this.jsctrl.on(cc.Node.EventType.TOUCH_CANCEL, this.on_end, this);
    }
  }, {
    key: "on_end",
    value: function on_end() {
      if (!$2DataManager.default.instance.is_over) {
        this.stick.setPosition(cc.v2(0, 0));
        this.dir = cc.v2(0, 0);
        $2EventsMgr.EventsManager.emit("play_sp", false);
        this.moving = false;
        this.node.setPosition(this.hbdian.position);
      }
    }
  }, {
    key: "on_move",
    value: function on_move(e) {
      if ($2DataManager.default.instance.is_over) {
        return;
      }
      this.moving || $2EventsMgr.EventsManager.emit("play_sp", true);
      this.moving = true;
      var t = e.getLocation();
      var a = this.node.convertToNodeSpaceAR(t);
      var n = a.mag();
      if (n < this.min_r) {
        this.stick.setPosition(a);
      } else {
        this.dir = a.normalize();
        if (n > this.max_r) {
          a.x = this.max_r * a.x / n, a.y = this.max_r * a.y / n;
        }
        this.stick.setPosition(a);
      }
    }
  }, {
    key: "on_start",
    value: function on_start(e) {
      if ($2DataManager.default.instance.is_over) {
        return;
      }
      this.moving = false;
      var t = e.getLocation();
      var a = this.node.parent.convertToNodeSpaceAR(t);
      this.node.setPosition(cc.v3(a.x, a.y, 0));
    }
  }, {
    key: "start",
    value: function start() {}
  }]);
  return r;
}(cc.Component);
def_JoyStickBall = cc__decorate([ccp_ccclass], def_JoyStickBall);
exports.default = def_JoyStickBall;